home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / fhprtsc.zip / HPRTSC.ASM < prev    next >
Assembly Source File  |  1993-05-01  |  11KB  |  374 lines

  1.     PAGE    ,132
  2.     TITLE    HPRTSC
  3.     SUBTTL    Description
  4.  
  5. ; Copyright (c) 1987, Background Processes
  6. ;
  7. ; Permission is hereby granted to copy, distribute, modify, include,
  8. ; burn, rape, or pillage this software in accordance with the following
  9. ; guidelines:
  10. ;
  11. ;    1) Distribution of this program is to be free. If a charge is made
  12. ;       for copying, it must be no more than $5 US. Permission for
  13. ;       inclusion into commercial products must be obtained individually.
  14. ;
  15. ;    2) Distribution of the program must include this complete source
  16. ;       code, or at least it should be made available. Software
  17. ;       exchange should not only be a way of getting free software,
  18. ;       but should also be a learning experience. The best way to
  19. ;       learn is to be able to read the source code.
  20. ;
  21. ;    3) You promise not to laugh at the code (at least not too hard). I'm
  22. ;       a PDP-11 programmer. If that doesn't mean anything to you, ask
  23. ;       a hacker friend about the advantages of orthogonal instruction sets
  24. ;       and REAL general registers.
  25. ;
  26. ;    4) If you find (or correct - hint, hint) any bugs in this program, I
  27. ;       would appreciate it if you would let me know. This way I can
  28. ;       learn, too.
  29. ;
  30. ; Alan Groupe
  31. ; Background Processes
  32. ; PO Box 6347
  33. ; Nashua, NH 03063-6347
  34.  
  35. ; This program implements a graphics screen dump from a Hercules
  36. ; monochrome graphics board. It is similar to the DOS GRAPHICS.COM in
  37. ; that it takes over the PrtSc interrupt.
  38.  
  39. ; When HPRTSC is typed at the DOS prompt, it grabs the PrtSc interrupt
  40. ; vector, and then issues a terminate and stay resident DOS function
  41. ; call. When the PrtSc key is pressed, this program checks the Hercules
  42. ; board to determine whether it is in text or graphics mode. If the
  43. ; board is in text mode, the program simply executes a far jump to the
  44. ; original PrtSc routine. If the board is in graphics mode, the program
  45. ; waits for a key to be pressed on the keyboard. If the '1' key is pressed,
  46. ; the program scans through the first graphics page (B0000 - B7FFF; called
  47. ; page 0 in the Hercules manual) and formats it for output on the printer.
  48. ; If the '2' key is pressed, the second graphics page (B8000 - BFFFF) is
  49. ; printed. If any other key is pressed, you will hear a short beep and HPRTSC
  50. ; will just return. You can use this to freeze an animated graphics display
  51. ; to look at it more closely. Just press PrtSc to freeze the screen. To
  52. ; unfreeze it, just press any key other than '1' or '2'.
  53. ; The dot mapping of a Hercules board is a little weird. Each byte in
  54. ; the graphics memory corresponds to eight dots horizontally, with the
  55. ; most significant bit of each byte representing the leftmost dot of the
  56. ; eight. There are 720 dots across on the display, so the first 90 bytes
  57. ; (B0000 - B005A) make up the first line on the screen (line 1).
  58. ; However, the next 90 bytes are not line 2, but rather line 5. The next
  59. ; 90 bytes, line 9. This continues down the screen until line 345
  60. ; (B1E3C). The remaining 170 bytes (B1E96 - B1FFF) are unused. Then the
  61. ; 90 byte groups starting at B2000 correspond to lines 2, 6, 10, etc.
  62. ; Therefore, lines 1-10 have the respective starting addresses B0000,
  63. ; B2000, B4000, B6000, B005A, B205A, B405A, B605A, B00B4, and B20B4.
  64. ; This, of course, is not even close to how an Epson printer maps dots
  65. ; on the paper. The Epson printer takes an eight bit byte and prints a
  66. ; column of 8 dots vertically, with the most significant bit at the top.
  67. ; Since the Hercules board is organized horizontally and the Epson printer
  68. ; is organized vertically, this program prints the screen image rotated 90
  69. ; degrees.
  70.  
  71.     SUBTTL    Entry Point
  72.     PAGE    +
  73.  
  74. cseg    segment
  75.     assume    cs:cseg,ds:cseg
  76.  
  77. ; This is the initial program entry point. It jumps to 'init' which sets
  78. ; up the interrupt vector, prints out a message confirming program load,
  79. ; and does a terminate and stay resident call.
  80.  
  81.     jmp    init    ; jump around real code to load in memory
  82.     SUBTTL    PrtSc Entry Point
  83.     PAGE    +
  84.  
  85. ; This is the entry point when PrtSc is pressed. It is ORG'ed at location
  86. ; 348 (minus 100h) to allow the previous 348 bytes, including the now
  87. ; unnecessary PSP to be used as a buffer to hold a full vertical scan of the
  88. ; screen. 
  89.  
  90.     org    348-100h
  91.  
  92. int5:
  93.     push    ax
  94.     push    bx
  95.     push    dx
  96.  
  97. ; First we must determine whether the Hercules board is in text mode or
  98. ; graphics mode. This is done with a program given to me by Hercules Computer
  99. ; Technology Inc. It isn't real clear to me why this program works the way it
  100. ; does, but it appears that if you force trip the light pen, it returns the
  101. ; character location (6845 meaning) just past the end of the screen. This may
  102. ; have something to do with the fact that there is no light pen receiving a
  103. ; raster pulse. If this is the case, I have no idea if this still works if you
  104. ; actually have a light pen connected.
  105.  
  106. ourstat    equ    03bah
  107. notvsync equ    80h
  108. lpreset    equ    03bbh
  109. lpset    equ    03b9h
  110. our6845    equ    03b4h
  111. threshold equ    (80*25 + 45*87)/2
  112.  
  113.     mov    dx,ourstat
  114.  
  115. w1:    in    al,dx        ; first, wait for vertical retrace
  116.     test    al,notvsync
  117.     jz    w1
  118.  
  119. w2:    in    al,dx        ; then make sure not to test during vertical
  120.     test    al,notvsync    ; retrace
  121.     jnz    w2
  122.  
  123.     xor    al,al        ; tickle light pen
  124.     mov    dx,lpreset
  125.     out    dx,al
  126.     mov    dx,lpset
  127.     out    dx,al
  128.  
  129.     mov    al,16        ; get high byte of lp trip offset
  130.     mov    dx,our6845
  131.     out    dx,al
  132.     inc    dx
  133.     in    al,dx
  134.     mov    bh,al
  135.  
  136.     mov    al,17        ; and low byte
  137.     mov    dx,our6845
  138.     out    dx,al
  139.     inc    dx
  140.     in    al,dx
  141.  
  142.     mov    ah,bh        ; return light pen trip address
  143.     cmp    ax,threshold
  144.     pop    dx        ; restore original user registers
  145.     pop    bx
  146.     pop    ax
  147.     ja    gprint        ; above threshold, in graphics mode
  148.  
  149. ; The following two lines are a 'jmp far' instruction to jump to the BIOS
  150. ; print screen routine if the Hercules board is in text mode. The location
  151. ; is filled in in the 'init' routine.
  152.  
  153. tjump:    db    0eah        ;! JMP FAR 0:0
  154.     dw    0,0
  155.  
  156.     SUBTTL    Graphics Entry Point
  157.     PAGE    +
  158.  
  159. ; This is the entry point if the Hercules board is in graphics mode.
  160.  
  161. gprint:
  162.     push    ax        ; save all registers
  163.     push    bx
  164.     push    cx
  165.     push    dx
  166.     push    si
  167.     push    di
  168.     push    bp
  169.     push    ds
  170.     push    es
  171.  
  172. ; First test location 50:0 to see if print screen is already in progress.
  173.  
  174.     mov    ax,50h
  175.     mov    ds,ax
  176.     cmp    byte ptr ds:0,1    ; prtsc already active?
  177.     mov    byte ptr ds:0,1    ; it is now
  178.     mov    ax,cs        ; retore ds:
  179.     mov    ds,ax
  180.     jnz    gp1        ; print screen in progress before? no.
  181.     jmp    exit        ; yes
  182. gp1:
  183.     xor    ax,ax        ; set for read char
  184.     int    16h        ; read char from keyboard
  185.     mov    dx,0b000h    ; assume page 1
  186.     cmp    al,'1'
  187.     je    gp3
  188.     mov    dx,0b800h    ; page 2
  189.     cmp    al,'2'
  190.     je    gp3
  191. ;
  192. ; neither '1' nor '2', so beep an error and return
  193. ;
  194. timer    equ    40h
  195. port_b    equ    61h
  196.  
  197.     mov    al,10110110b    ; sel tim 2,lsb,msb,binary
  198.     out    timer+3,al    ; write the timer mode reg
  199.     mov    ax,533h        ; divisor for 1000 hz
  200.     out    timer+2,al    ; write timer 2 cnt - lsb
  201.     mov    al,ah
  202.     out    timer+2,al    ; write timer 2 cnt - msb
  203.     in    al,port_b    ; get current setting of port
  204.     mov    ah,al        ; save that setting
  205.     or    al,03        ; turn speaker on
  206.     out    port_b,al
  207.     sub    cx,cx        ; set count to 500 ms
  208. gp2:    loop    gp2        ; delay before turning off
  209.     mov    al,ah        ; recover value of port
  210.     out    port_b,al
  211.     jmp    done    
  212.  
  213. ;
  214. ; set up printer for graphics printing
  215. ;
  216. gp3:    mov    ds,dx        ; segment address of page requested
  217.     push    cs        ; es points to work area which is at
  218.     pop    es        ;  beginning of code segment
  219.     xor    dx,dx        ; printer number is zero (LPT1)
  220.     xor    si,si        ; horizontal offset (start at left edge)
  221.  
  222.     mov    ax,27        ; select 8/72" line feeds (ESC A 8)
  223.     int    17h
  224.     mov    ax,'A'
  225.     int    17h
  226.     mov    ax,8
  227.     int    17h
  228.     mov    ax,27        ; set selection in force (ESC 2)
  229.     int    17h
  230.     mov    ax,'2'
  231.     int    17h
  232.  
  233. ; start running through screen starting with lower left corner, working up
  234. ; and then to the right
  235. ;
  236. ; l1 is loop for each vertical pass. This is also one print line.
  237.  
  238. l1:    mov    bx,1e3ch    ; bottom-most scan line in first quadrant
  239.     mov    cx,87        ; # horizontal lines in a quadrant (348/4)
  240.        xor    di,di        ; pointer into ES: work area (beginning of code)
  241.  
  242. l2:    mov    al,6000h[bx+si]    ; get character from quadrant 4 scan line
  243.     stosb            ; and store in work area
  244.     cmp    al,0        ; if it was other than a zero, store new
  245.     je    $+4        ; of di in dx so dx will be length of line to
  246.     mov    dx,di        ; print (null truncated)
  247.  
  248.     mov    al,4000h[bx+si]    ; do likewise for third quadrant
  249.     stosb
  250.     cmp    al,0
  251.     je    $+4
  252.     mov    dx,di
  253.  
  254.     mov    al,2000h[bx+si]    ; and second
  255.     stosb
  256.     cmp    al,0
  257.     je    $+4
  258.     mov    dx,di
  259.  
  260.     mov    al,[bx+si]    ; and the first quadrant
  261.     stosb
  262.     cmp    al,0
  263.     je    $+4
  264.     mov    dx,di
  265.  
  266.     sub    bx,5ah        ; up one horizontal scan line (90 bytes)
  267.     loop    l2        ;  (effectively 4 horizontal scan lines)
  268.  
  269.     cmp    dx,0        ; completely blank vertical line?
  270.     je    l5        ; don't print, just advance paper
  271.     push    dx        ; save length of line to print
  272.     xor    dx,dx        ; for printer zero, again
  273.     mov    cx,10        ; count for left margin (ie, 10 spaces)
  274. l3:    mov    ax,' '        ; the print them
  275.     int    17h
  276.     loop    l3
  277.     mov    ax,27        ; then print the graphics line
  278.     int    17h        
  279.     mov    ax,'L'        ; ESC L introduction (double density)
  280.     int    17h
  281.     pop    cx        ; length of line to print
  282.     shl    cx,1        ; *2 since we print double for double density
  283.     mov    ax,cx
  284.     xor    ah,ah        ; get least significant byte
  285.     int    17h        ; and send it
  286.     xor    ah,ah
  287.     mov    al,ch        ; then get most significant byte
  288.     int    17h        ; and send it
  289.     shr    cx,1        ; then shift back down to real count
  290.  
  291.     push    si        ; save horizontal offset
  292.     xor    si,si        ; point to save graphics line
  293. l4:    lods    byte ptr cs:0    ; get a character to print
  294.     xor    ah,ah
  295.     push    ax        ; BUG: my clone BIOS' int 17 stomps on AL
  296.     int    17h        ; and print it
  297.     pop    ax        ; restore due to my BIOS' bug
  298.     int    17h        ; print a second time for increased density
  299.     loop    l4        ; till end of line
  300.     pop    si        ; and restore horizontal offset for next pass
  301.  
  302. l5:    mov    ax,0dh        ; now do a CRLF
  303.     int    17h
  304.     mov    ax,0ah
  305.     int    17h
  306.     
  307.     inc    si        ; move one space to the right
  308.     cmp    si,5ah        ; already on right hand edge?
  309.     jae    l6        ; yes
  310.     jmp    l1        ; no, do another vertical pass
  311. l6:
  312.     
  313.     mov    ax,27        ; set the printer back to 6lpi
  314.     int    17h        ;  (even if it was at 8lpi)
  315.     mov    ax,'2'
  316.     int    17h
  317.     mov    ax,12        ; really 12/72 of an inch
  318.     int    17h
  319.  
  320. done:    mov    ax,50h
  321.     mov    ds,ax
  322.     mov    byte ptr ds:0,0    ; prtsc is now over
  323.  
  324. exit:
  325.     pop    es        ; restore all registers
  326.     pop    ds
  327.     pop    bp
  328.     pop    di
  329.     pop    si
  330.     pop    dx
  331.     pop    cx
  332.     pop    bx
  333.     pop    ax
  334.  
  335.     iret            ; and return to what user was doing
  336.     SUBTTL    Initial Entry Point (Setup)
  337.     PAGE    +
  338. ; This is the code executed the first time the program is invoked. It first
  339. ; builds a jump instruction at location 'tjump' that jumps to the BIOS print
  340. ; screen routine when the Hercules board is in text mode. Then it loads the
  341. ; print screen vector to point to the entry point and issues a terminate and
  342. ; stay resident call.
  343.  
  344. init:
  345.     mov    ax,ds:2ch
  346.     mov    es,ax        ; segment address of environment strings
  347.     mov    ah,49h        ; deallocate our copy of environment strings
  348.     int    21h
  349.     mov    ax,3505h        ; get address for normal print screen
  350.     int    21h
  351.     mov    ax,es
  352.     mov    word ptr tjump+103h,ax    ; store segment address in jmp instr.
  353.     mov    word ptr tjump+101h,bx    ; likewise with offset
  354.  
  355.     mov    dx,offset int5+100h
  356.     mov    ax,2505h        ; grab print screen interrupt vector
  357.     int    21h
  358.  
  359.     mov    dx,offset announce+100h
  360.     mov    ah,09h            ; print announcement
  361.     int    21h
  362.     mov    dx,offset init+100h    ; lock program in memory
  363.     int    27h
  364.  
  365. announce:
  366.     db    0dh,0ah,'HPrtSc - Graphics Screen Dump, Version 1.00',0dh,0ah
  367.     db    'Copyright (c) 1987, Background Processes',0dh,0ah,'$'
  368.  
  369. cseg    ends
  370.     end
  371.